#include "beweging_detect.h"

void beweging_detector()
{

	VideoCapture camera;
	namedWindow("cameraOutput", CV_WINDOW_AUTOSIZE);
	namedWindow("resultImage", CV_WINDOW_AUTOSIZE);

	Mat frame;
	Mat image;
	Mat result;
	char key;
	bool MotionOn = true;

	camera.open(1);

	camera >> frame;
	frame.copyTo(image);
	imshow("cameraOutput", image);

	while(MotionOn){
		camera >> frame;

		frame.copyTo(image);
		cvtColor(image, result, CV_BGR2GRAY);
		result = result > 128;

		if(cvWaitKey(100) != -1)
		{
			MotionOn = false;
		};

		imshow("cameraOutput", image);
		imshow("resultImage", result);
	}
	//Clean up windows an camera object
	cvDestroyAllWindows();
	camera.release();

}